<?php
class RichengModel extends Model {
	public function get_now($date)   //获取日程   $date为2009-10-16格式的字符串
	{
		$l = M();   //实例化一个Model
		$list=$l->query("SELECT * FROM richeng,user where user.user_id=richeng.user_id and rc_date='{$date}' and gk=1 order by richeng.user_id");
		return $list;
	}
	function get_user_rc($id)   //获取某个用户的日程  $id为用户的id号
	{
		$l = M();   //实例化一个Model
		$list=$l->query("SELECT * FROM richeng,user where user.user_id=richeng.user_id and richeng.user_id={$id} and gk=1 order by richeng.rc_date");
		return $list;
	}
        function get_all_richeng(){
            $sql="select rc_id,rc_date,rc_time,rc_body,user_name from richeng,user where richeng.user_id=user.user_id order by rc_date";
            return $this->query($sql);
        }
        public function get_between_rc($begin_date,$end_date)   //获取某个日期段的日程  $begin_date=开始日期   $end_date=结束日期
	{
		$l = M();   //实例化一个Model
		$list=$l->query("SELECT * FROM richeng,user "
                    ."where (user.user_id=richeng.user_id) and (richeng.rc_date between {$begin_date} and {$end_date}) "
                    ."and gk=1 order by richeng.rc_date,richeng.user_id");
		return $list;
	}
        function get_user($id)   //获取某个用户自己的全部日程
        {
            $list=$this->query("SELECT * FROM richeng where user_id={$id} order by rc_date desc");
            return $list;
        }


        //对用户的日程的公开状态进行替换
        function rc_gk_replace($list){
            for($i=0;$i<count($list);$i++)
             {
                if($list[$i]['gk']==0)
                    $list[$i]['gk']='私有';
                else
                    $list[$i]['gk']='公开';
             }
            return $list;
        }
}
?>